<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<html>
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <%
        pageContext.setAttribute("APP_PATH", request.getContextPath());
    %>
    <script src="https://cdn.jsdelivr.net/npm/jquery@1.12.4/dist/jquery.min.js"></script>
    <link href="https://cdn.jsdelivr.net/npm/bootstrap@3.3.7/dist/css/bootstrap.min.css" rel="stylesheet">
    <!-- 加载 Bootstrap 的所有 JavaScript 插件。你也可以根据需要只加载单个插件。 -->
    <script src="https://cdn.jsdelivr.net/npm/bootstrap@3.3.7/dist/js/bootstrap.min.js"></script>
    <style>
        .child {
            width: 100%;
            height: 30%;
        }
    </style>
</head>
<body>
<jsp:include page="admin_header.jsp"/>
<div class="container">
    <div class="container child">
        <label><br/>请输入内容：<br/></label>
        <textarea class="form-control " rows="5"></textarea>
    </div>

    <div class="container ">
        <label>请输入有效期：</label>
        <input type="text" name="end" id="end" placeholder="如：2021624"/>

    </div>

    <div class="row " style="height: 50%">
        <div class="col-md-12" style="height:250px; overflow:scroll;">
            <table class="table table-hover" id="choose_table">
                <thead>
                <tr>
                    <th>教师Id</th>
                    <th>教师姓名</th>
                    <th>教师性别</th>
                    <th>操作</th>
                </tr>
                </thead>
                <tbody>
                </tbody>
            </table>
        </div>

    </div>
</div>

<script type="text/javascript">

    $(function () {
        //去首页
        // to_page("/getTeacherList");
        to_page("/getTeacherListNotLogOut");
    });

    function to_page(road) {
        $.ajax({
            url: "${APP_PATH}" + road,
            //data:"pn="+pn,
            type: "GET",
            success: function (result) {
                build_check_paper(result);
            }
        });
    }

    //1、解析并显示数据
    function build_check_paper(result) {
        //清空table表格
        $("#choose_table tbody").empty();
        var emps = result.data;
        $.each(emps, function (index, item) {
            var teacherIdTd = $("<td></td>").append(item.teacherid);
            var teacherNameTd = $("<td></td>").append(item.teachername);

            var teacherSexTd = $("<td></td>");
            if (item.teachersex == 1) {
                teacherSexTd.append("女");
            }
            if (item.teachersex == 2) {
                teacherSexTd.append("男");
            }


            var sendBtn = $("<button></button>").addClass("btn btn-success btn-sm sendBtn")
                .append($("<span></span>").addClass("glyphicon glyphicon-ok")
                    .append(" 发送"));
            sendBtn.attr("id", item.teacherid); //点击该按钮时 绑定相应的item值

            $("<tr></tr>").append(teacherIdTd).append(teacherNameTd)
                .append(teacherSexTd).append(sendBtn)
                .appendTo("#choose_table tbody");
        });
    }

    $(document).on("click", ".sendBtn", function () {
        var message = $("textarea").val();
        var end = $("#end").val();

        $.ajax({
            url: "${APP_PATH}/sendMessageToTeacher",
            type: "GET",
            data: {"teacherid": $(this).attr("id"), "message": message, "end": end},
            success: function (result) {
                alert(result.message)
                $("textarea").val('')
            },
            error: function (error) {
                alert("请填写完整!")
            }
        });
    });
</script>
</body>
</html>
